#ifndef __IPC_EXCEPTION_HPP__
#define __IPC_EXCEPTION_HPP__

namespace ipc {

// Excepcion basica de los envoltorios de objetos IPC.
class exception : public std::runtime_error {
	protected:
		key_t key;
		int id;
	public:
		explicit exception (const std::string& message) : std::runtime_error(message) {
			this->key = 0;
			this->id = 0;
		};

		exception (int id, key_t key, const std::string& message) : std::runtime_error(message) {
			this->id = id;
			this->key = key;
		}
		int getId() const {
			return this->id;
		}
		int getKey() const {
			return key;
		}

		virtual std::string getClass() const {
			return "exception";
		}

		virtual const char* what() const throw() {
			static std::stringstream ss;
				
			ss.str("");
			ss.clear();
			ss << getClass() << "{id=" << getId() << ",key=" << std::hex << getKey() << "}: " << std::runtime_error::what();
			return ss.str().c_str();
		}
}; // class exception


template <typename T>
inline void assert (bool condicion, const std::string& message, const T& t) throw(exception) {
	if (!condicion)
		throw exception(t.getId(),t.getKey(),message);
}

} // namespace ipc

#endif /* __IPC_EXCEPTION_HPP__ */

